Why do I get error "prefix [..] is not defined" when I try to use my jsf custom tag?
Posted
by Roman
on Stack Overflow
See other posts from Stack Overflow
or by Roman
Published on 2010-04-26T15:05:34Z
Indexed on
2010/04/26
15:23 UTC
Read the original article
Hit count: 325
I created a jsf custom tag (I'm not sure that it's correct, I could miss something easily, so I attached code below).
Now I'm trying to use this tag but I get an error:
error on line 28 at column 49: Namespace prefix gc on ganttchart is not defined
So, here is the xhtml-page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:gc="http://myganttchart.org">
<body>
<ui:composition template="/masterpage.xhtml">
<ui:define name="title">Gantt chart test</ui:define>
<ui:define name="content">
<f:view>
<gc:ganttchart width="300" height="100" rendered="true"/>
...
</f:view>
</ui:define>
</ui:composition>
</body>
</html>
And here is tld
-file (it's placed in WEB-INF/
):
<taglib xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1">
<tlib-version>
1.0
</tlib-version>
<short-name>
oext
</short-name>
<uri>
http://myganttchart.org
</uri>
<tag>
<name>ganttchart</name>
<tag-class>usermanagement.support.ganttchart.GanttChartTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>binding</name>
<deferred-value>
<type>javax.faces.component.UIComponent</type>
</deferred-value>
</attribute>
...
</tag>
</tablib>
Here is a part of tag-class
code:
public class GanttChartTag extends UIComponentELTag {
private ValueExpression width;
private ValueExpression height;
private ValueExpression styleClass;
public String getComponentType () {
return "org.myganttchart";
}
public String getRendererType () {
return null;
}
...
}
Correspondent block from faces-config
:
<component>
<component-type>org.myganttchart</component-type>
<component-class>usermanagement.support.ganttchart.UIGanttChart</component-class>
</component>
And the last part if UIGanttChart
:
public class UIGanttChart extends UIOutput {
public UIGanttChart() {
setRendererType (null);
}
//some test code
public void encodeBegin(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter ();
writer.startElement("img", this);
writer.writeAttribute("src", "no-img", "source");
writer.writeAttribute("width", getAttributes ().get ("width"), "width");
writer.writeAttribute("height", getAttributes ().get ("height"), "height");
writer.writeAttribute("class", ".someclass", "styleClass");
writer.endElement("img");
}
}
So, what did I miss?
© Stack Overflow or respective owner